package io.netty.server.discard;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.ReferenceCountUtil;

/**
 * 服务端消息处理 handler
 * @author lianlb
 *
 */
public class DiscardServerHandler extends ChannelHandlerAdapter {
	
//	private static final Logger log = LogManager.getLogger(DiscardServerHandler.class);

	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
		try {
//			log.info("消息：{" + msg + "}");
			System.out.println("处理器消息：[" + msg + "]");
		} finally {
			ReferenceCountUtil.release(msg);
		}
	}
	
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		cause.printStackTrace();
		ctx.close();
	}

}
